package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.WslcmMapper;
import com.gxa.pojo.Lacost;
import com.gxa.pojo.StoneColor;
import com.gxa.service.WslcmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zxy
 * Date: 2020/11/02 17:15
 * Description:
 * Version: V1.0
 */
@Service
public class WslcmServiceImpl implements WslcmService{

    @Autowired(required = false)
    private WslcmMapper wslcmMapper;

    @Override
    public int addLacost(Lacost lacost) {
        return wslcmMapper.addLacost(lacost);
    }
    @Override
    public PaginationResult queryLacost(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeWslcm();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Lacost> lacostList =  wslcmMapper.queryLacost(param1,param2);
        paginationResult.setData(lacostList);
        return paginationResult;
    }

    @Override
    public int updateLacost(Lacost lacost) {
        return wslcmMapper.updateLacost(lacost);
    }

    @Override
    public int delLacost(int lacostId) {
        return wslcmMapper.delLacost(lacostId);
    }

    public int getTotalSizeWslcm() {
        return wslcmMapper.getTotalSizeWslcm();
    }
}
